package com.wuzhao.resume.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuzhao.resume.common.util.FileUtils;
import com.wuzhao.resume.entity.ResumeDO;
import com.wuzhao.resume.entity.ResumeFile;
import com.wuzhao.resume.mapper.ResumeMapper;
import com.wuzhao.resume.service.ResumeFileService;
import com.wuzhao.resume.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author： M1nG
 * @since： 2020-10-17 15:37:23
 * @description： 简历 服务实现类
 * @version： 1.0
 */
@Service
@Transactional
public class ResumeServiceImpl extends ServiceImpl<ResumeMapper, ResumeDO> implements ResumeService {

    @Autowired
    private ResumeService resumeService;

    @Autowired
    private ResumeFileService resumeFileService;

    @Override
    public void saveOrUpdateBatchs(List<ResumeDO> resumeDO) {
        resumeService.saveOrUpdateBatch(resumeDO);
    }

    @Override
    public void removeByIdList(List<Integer> idList) {
        resumeService.removeByIds(idList);
    }

    @Override
    public void updateByResume(ResumeDO resume) {
        resumeService.updateById(resume);
    }

    @Override
    public void SaveOrUpdate(Map<String, String> resultMap) {
        //存入文件表
        ResumeFile resumeFile = new ResumeFile();
        resumeFile.setName(resultMap.get("newName"));
        resumeFile.setOldName(resultMap.get("oldName"));
        resumeFile.setFilePath(resultMap.get("path"));
        resumeFileService.save(resumeFile);

        //把file_id和状态存入resume表
        //Map<String,String> parseResult = FileUtils.readWordOrPdf(resultMap.get("path"));
        Map<String,String> parseResult = FileUtils.parseText(resultMap.get("oldName"));

        ResumeDO resumeDO = new ResumeDO();
        resumeDO.setFileId(resumeFile.getId());
        resumeDO.setName(parseResult.get("name"));
        resumeDO.setDistrict(parseResult.get("district"));
        resumeDO.setJob(parseResult.get("job"));
        resumeDO.setSalary(parseResult.get("salary"));
        resumeDO.setMobileNumber(parseResult.get("mobileNumber"));
        resumeService.save(resumeDO);
    }
}
